import java.util.Stack;

/*
 * @author zzr
 * @date: 2025/10/14  20:46
 * @description: 用栈实现队列
 */
public class MyQueue {
    private Stack<Integer> s1;
    private Stack<Integer> s2;

    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public boolean empty() {
        return s1.isEmpty() && s2.isEmpty();
    }
    public void push(int x) {
        s1.push(x);
    }
    public int pop() {
        if (empty()) {
            return -1;
        }
        if (s2.isEmpty()) {
            int size = s1.size();
            for (int i = 0; i < size; i++) {
                int tmp = s1.pop();
                s2.push(tmp);
            }
        }
        return s2.pop();
    }
    public int peek() {
        if (empty()) {
            return -1;
        }
        if (s2.isEmpty()) {
            int size = s1.size();
            for (int i = 0; i < size; i++) {
                int tmp = s1.pop();
                s2.push(tmp);
            }
        }
        return s2.peek();
    }
}
